package pers.qianyu.month_202012.date_20201228;

import java.util.*;

/**
 * 7. 混合背包问题
 * https://www.acwing.com/problem/content/7/
 *
 * @author mizzle rain
 * @date 2020年12月28日16:28:30
 */
public class BagMixing {
    private int N;
    private int V;
    // 体积
    private int[] v;
    // 价值
    private int[] w;
    // 个数
    private int[] s;

    public void input() {
        Scanner sc = new Scanner(System.in);
        String[] line = sc.nextLine().split(" ");
        N = Integer.parseInt(line[0]);
        V = Integer.parseInt(line[1]);
        v = new int[N];
        w = new int[N];
        s = new int[N];
        for (int i = 0; i < N; i++) {
            v[i] = sc.nextInt();
            w[i] = sc.nextInt();
            s[i] = sc.nextInt();
        }
        sc.close();
    }

    private static class Good {
        int volume;
        int weight;
        int kind;

        public Good(int volume, int weight, int kind) {
            this.volume = volume;
            this.weight = weight;
            this.kind = kind;
        }
    }

    public int solve() {
        ArrayList<Good> goods = new ArrayList<>();
        for (int i = 0; i < N; i++) {
            int volume = v[i];
            int weight = w[i];
            int size = s[i];
            if (size == -1) {
                // 01 背包
                goods.add(new Good(volume, weight, -1));
            } else if (size == 0) {
                // 完全背包
                goods.add(new Good(volume, weight, 0));
            } else {
                // 多重背包
                for (int k = 1; k <= size; k *= 2) {
                    size -= k;
                    goods.add(new Good(volume * k, weight * k, -1));
                }
                if (size > 0) {
                    goods.add(new Good(volume * size, weight * size, -1));
                }
            }
        }
        int[] dp = new int[V + 1];
        for (Good good : goods) {
            if (good.kind == -1) {
                for (int i = V; i >= good.volume; i--) {
                    dp[i] = Math.max(dp[i], dp[i - good.volume] + good.weight);
                }
            } else {
                for (int i = good.volume; i <= V; i++) {
                    dp[i] = Math.max(dp[i], dp[i - good.volume] + good.weight);
                }
            }
        }
        return dp[V];
    }

    public static void main(String[] args) {
        BagMixing bag = new BagMixing();
        bag.input();
        int result = bag.solve();
        System.out.println(result);
    }
}
